package com.sayice.coursetable.ui.score;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sayice.coursetable.R;
import com.sayice.coursetable.logic.model.Score;

import java.util.List;

/**
 * 成绩适配器
 */
public class ScoreAdapter extends RecyclerView.Adapter<ScoreAdapter.ViewHolder> {
    private final List<Score> scoreList;

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView courseName;
        private final TextView mark;
        private final TextView credit;
        private final TextView gradePoint;
        private final TextView type;
        private final TextView term;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            courseName = itemView.findViewById(R.id.courseName);
            mark = itemView.findViewById(R.id.mark);
            credit = itemView.findViewById(R.id.credit);
            gradePoint = itemView.findViewById(R.id.gradePoint);
            type = itemView.findViewById(R.id.type);
            term = itemView.findViewById(R.id.term);
        }
    }

    public ScoreAdapter(@NonNull List<Score> scoreList) {
        this.scoreList = scoreList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
        View view = layoutInflater.inflate(R.layout.score_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
        Score score = scoreList.get(position);
        viewHolder.courseName.setText(score.courseName);
        viewHolder.mark.setText(score.mark);
        viewHolder.credit.setText(String.valueOf(score.credit));
        viewHolder.gradePoint.setText(String.valueOf(score.gradePoint));
        viewHolder.type.setText(score.type);
        viewHolder.term.setText(score.term);
    }

    @Override
    public int getItemCount() {
        return scoreList.size();
    }
}
